/*   1:    */ package org.intellij.images.util;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.util.io.UnsyncByteArrayInputStream;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.DataInput;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.RandomAccessFile;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */ 
/*  12:    */ public class ImageInfoReader
/*  13:    */ {
/*  14: 29 */   private static final Logger a = Logger.getInstance("#org.intellij.images.util.ImageInfoReader");
/*  15:    */   
/*  16:    */   @Nullable
/*  17:    */   public static Info getInfo(@NotNull String paramString)
/*  18:    */   {
/*  19: 36 */     if (paramString == null) {
/*  20: 36 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/images/util/ImageInfoReader", "getInfo" }));
/*  21:    */     }
/*  22: 36 */     return a(paramString);
/*  23:    */   }
/*  24:    */   
/*  25:    */   @Nullable
/*  26:    */   public static Info getInfo(@NotNull byte[] paramArrayOfByte)
/*  27:    */   {
/*  28: 41 */     if (paramArrayOfByte == null) {
/*  29: 41 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/images/util/ImageInfoReader", "getInfo" }));
/*  30:    */     }
/*  31: 41 */     return a(paramArrayOfByte);
/*  32:    */   }
/*  33:    */   
/*  34:    */   @Nullable
/*  35:    */   private static Info a(@NotNull String paramString)
/*  36:    */   {
/*  37: 49 */     if (paramString == null) {
/*  38: 49 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/images/util/ImageInfoReader", "read" }));
/*  39:    */     }
/*  40:    */     try
/*  41:    */     {
/*  42: 49 */       RandomAccessFile localRandomAccessFile = new RandomAccessFile(paramString, "r");
/*  43:    */       try
/*  44:    */       {
/*  45: 51 */         return a(localRandomAccessFile);
/*  46:    */       }
/*  47:    */       finally
/*  48:    */       {
/*  49:    */         try
/*  50:    */         {
/*  51: 55 */           localRandomAccessFile.close();
/*  52:    */         }
/*  53:    */         catch (IOException localIOException3) {}
/*  54:    */       }
/*  55: 63 */       return null;
/*  56:    */     }
/*  57:    */     catch (IOException localIOException1) {}
/*  58:    */   }
/*  59:    */   
/*  60:    */   @Nullable
/*  61:    */   private static Info a(@NotNull byte[] paramArrayOfByte)
/*  62:    */   {
/*  63: 69 */     if (paramArrayOfByte == null) {
/*  64: 69 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/images/util/ImageInfoReader", "read" }));
/*  65:    */     }
/*  66: 69 */     DataInputStream localDataInputStream = new DataInputStream(new UnsyncByteArrayInputStream(paramArrayOfByte));
/*  67:    */     try
/*  68:    */     {
/*  69: 71 */       return a(localDataInputStream);
/*  70:    */     }
/*  71:    */     catch (IOException localIOException1)
/*  72:    */     {
/*  73: 74 */       return null;
/*  74:    */     }
/*  75:    */     finally
/*  76:    */     {
/*  77:    */       try
/*  78:    */       {
/*  79: 78 */         localDataInputStream.close();
/*  80:    */       }
/*  81:    */       catch (IOException localIOException4) {}
/*  82:    */     }
/*  83:    */   }
/*  84:    */   
/*  85:    */   @Nullable
/*  86:    */   private static Info a(@NotNull DataInput paramDataInput)
/*  87:    */     throws IOException
/*  88:    */   {
/*  89: 89 */     if (paramDataInput == null) {
/*  90: 89 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/images/util/ImageInfoReader", "readFileData" }));
/*  91:    */     }
/*  92: 89 */     int i = paramDataInput.readUnsignedByte();
/*  93: 90 */     int j = paramDataInput.readUnsignedByte();
/*  94: 92 */     if ((i == 71) && (j == 73)) {
/*  95: 93 */       return b(paramDataInput);
/*  96:    */     }
/*  97: 96 */     if ((i == 137) && (j == 80)) {
/*  98: 97 */       return d(paramDataInput);
/*  99:    */     }
/* 100:100 */     if ((i == 255) && (j == 216)) {
/* 101:101 */       return c(paramDataInput);
/* 102:    */     }
/* 103:108 */     return null;
/* 104:    */   }
/* 105:    */   
/* 106:    */   @Nullable
/* 107:    */   private static Info b(DataInput paramDataInput)
/* 108:    */     throws IOException
/* 109:    */   {
/* 110:113 */     byte[] arrayOfByte1 = { 70, 56, 55, 97 };
/* 111:114 */     byte[] arrayOfByte2 = { 70, 56, 57, 97 };
/* 112:115 */     byte[] arrayOfByte3 = new byte[11];
/* 113:    */     
/* 114:117 */     paramDataInput.readFully(arrayOfByte3);
/* 115:118 */     if ((!a(arrayOfByte3, 0, arrayOfByte2, 0, 4)) && (!a(arrayOfByte3, 0, arrayOfByte1, 0, 4))) {
/* 116:119 */       return null;
/* 117:    */     }
/* 118:122 */     int i = d(arrayOfByte3, 4);
/* 119:123 */     int j = d(arrayOfByte3, 6);
/* 120:    */     
/* 121:125 */     int k = arrayOfByte3[8] & 0xFF;
/* 122:126 */     int m = (k >> 4 & 0x7) + 1;
/* 123:    */     
/* 124:128 */     return new Info(i, j, m);
/* 125:    */   }
/* 126:    */   
/* 127:    */   private static Info a(RandomAccessFile paramRandomAccessFile)
/* 128:    */     throws IOException
/* 129:    */   {
/* 130:132 */     byte[] arrayOfByte = new byte[44];
/* 131:133 */     if (paramRandomAccessFile.read(arrayOfByte) != arrayOfByte.length) {
/* 132:134 */       return null;
/* 133:    */     }
/* 134:137 */     int i = c(arrayOfByte, 16);
/* 135:138 */     int j = c(arrayOfByte, 20);
/* 136:140 */     if ((i < 1) || (j < 1)) {
/* 137:141 */       return null;
/* 138:    */     }
/* 139:144 */     int k = d(arrayOfByte, 26);
/* 140:145 */     if ((k != 1) && (k != 4) && (k != 8) && (k != 16)) {
/* 141:145 */       if (((k != 24 ? 1 : 0) & (k != 32 ? 1 : 0)) != 0) {
/* 142:146 */         return null;
/* 143:    */       }
/* 144:    */     }
/* 145:149 */     return new Info(i, j, k);
/* 146:    */   }
/* 147:    */   
/* 148:    */   @Nullable
/* 149:    */   private static Info c(DataInput paramDataInput)
/* 150:    */     throws IOException
/* 151:    */   {
/* 152:154 */     byte[] arrayOfByte = new byte[13];
/* 153:    */     for (;;)
/* 154:    */     {
/* 155:156 */       paramDataInput.readFully(arrayOfByte, 0, 4);
/* 156:    */       
/* 157:158 */       int i = a(arrayOfByte, 0);
/* 158:159 */       int j = a(arrayOfByte, 2);
/* 159:161 */       if ((i & 0xFF00) != 65280) {
/* 160:162 */         return null;
/* 161:    */       }
/* 162:165 */       if (i == 65504)
/* 163:    */       {
/* 164:166 */         if (j < 14)
/* 165:    */         {
/* 166:167 */           paramDataInput.skipBytes(j - 2);
/* 167:    */         }
/* 168:    */         else
/* 169:    */         {
/* 170:171 */           paramDataInput.readFully(arrayOfByte, 0, 12);
/* 171:172 */           paramDataInput.skipBytes(j - 14);
/* 172:    */         }
/* 173:    */       }
/* 174:    */       else
/* 175:    */       {
/* 176:174 */         if ((i >= 65472) && (i <= 65487) && (i != 65476) && (i != 65480))
/* 177:    */         {
/* 178:175 */           paramDataInput.readFully(arrayOfByte, 0, 6);
/* 179:    */           
/* 180:177 */           int k = (arrayOfByte[0] & 0xFF) * (arrayOfByte[5] & 0xFF);
/* 181:178 */           int m = a(arrayOfByte, 3);
/* 182:179 */           int n = a(arrayOfByte, 1);
/* 183:    */           
/* 184:181 */           return new Info(m, n, k);
/* 185:    */         }
/* 186:184 */         paramDataInput.skipBytes(j - 2);
/* 187:    */       }
/* 188:    */     }
/* 189:    */   }
/* 190:    */   
/* 191:    */   @Nullable
/* 192:    */   private static Info d(DataInput paramDataInput)
/* 193:    */     throws IOException
/* 194:    */   {
/* 195:191 */     byte[] arrayOfByte1 = { 78, 71, 13, 10, 26, 10 };
/* 196:192 */     byte[] arrayOfByte2 = new byte[27];
/* 197:    */     
/* 198:194 */     paramDataInput.readFully(arrayOfByte2);
/* 199:195 */     if (!a(arrayOfByte2, 0, arrayOfByte1, 0, 6)) {
/* 200:196 */       return null;
/* 201:    */     }
/* 202:199 */     int i = b(arrayOfByte2, 14);
/* 203:200 */     int j = b(arrayOfByte2, 18);
/* 204:201 */     int k = arrayOfByte2[22] & 0xFF;
/* 205:202 */     int m = arrayOfByte2[23] & 0xFF;
/* 206:203 */     if ((m == 2) || (m == 6)) {
/* 207:204 */       k *= 3;
/* 208:    */     }
/* 209:207 */     return new Info(i, j, k);
/* 210:    */   }
/* 211:    */   
/* 212:    */   private static int a(byte[] paramArrayOfByte, int paramInt)
/* 213:    */   {
/* 214:211 */     return (paramArrayOfByte[paramInt] & 0xFF) << 8 | paramArrayOfByte[(paramInt + 1)] & 0xFF;
/* 215:    */   }
/* 216:    */   
/* 217:    */   private static boolean a(byte[] paramArrayOfByte1, int paramInt1, byte[] paramArrayOfByte2, int paramInt2, int paramInt3)
/* 218:    */   {
/* 219:215 */     while (paramInt3-- > 0) {
/* 220:216 */       if (paramArrayOfByte1[(paramInt1++)] != paramArrayOfByte2[(paramInt2++)]) {
/* 221:217 */         return false;
/* 222:    */       }
/* 223:    */     }
/* 224:221 */     return true;
/* 225:    */   }
/* 226:    */   
/* 227:    */   private static int b(byte[] paramArrayOfByte, int paramInt)
/* 228:    */   {
/* 229:225 */     return (paramArrayOfByte[paramInt] & 0xFF) << 24 | (paramArrayOfByte[(paramInt + 1)] & 0xFF) << 16 | (paramArrayOfByte[(paramInt + 2)] & 0xFF) << 8 | paramArrayOfByte[(paramInt + 3)] & 0xFF;
/* 230:    */   }
/* 231:    */   
/* 232:    */   private static int c(byte[] paramArrayOfByte, int paramInt)
/* 233:    */   {
/* 234:229 */     return (paramArrayOfByte[(paramInt + 3)] & 0xFF) << 24 | (paramArrayOfByte[(paramInt + 2)] & 0xFF) << 16 | (paramArrayOfByte[(paramInt + 1)] & 0xFF) << 8 | paramArrayOfByte[paramInt] & 0xFF;
/* 235:    */   }
/* 236:    */   
/* 237:    */   private static int d(byte[] paramArrayOfByte, int paramInt)
/* 238:    */   {
/* 239:233 */     return paramArrayOfByte[paramInt] & 0xFF | (paramArrayOfByte[(paramInt + 1)] & 0xFF) << 8;
/* 240:    */   }
/* 241:    */   
/* 242:    */   public static class Info
/* 243:    */   {
/* 244:    */     public int width;
/* 245:    */     public int height;
/* 246:    */     public int bpp;
/* 247:    */     
/* 248:    */     public Info(int paramInt1, int paramInt2, int paramInt3)
/* 249:    */     {
/* 250:242 */       this.width = paramInt1;
/* 251:243 */       this.height = paramInt2;
/* 252:244 */       this.bpp = paramInt3;
/* 253:    */     }
/* 254:    */   }
/* 255:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.images.util.ImageInfoReader

 * JD-Core Version:    0.7.0.1

 */